import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/xl/xlCustomerShipment/list',
  save='/xl/xlCustomerShipment/add',
  edit='/xl/xlCustomerShipment/edit',
  deleteOne = '/xl/xlCustomerShipment/delete',
  deleteBatch = '/xl/xlCustomerShipment/deleteBatch',
  importExcel = '/xl/xlCustomerShipment/importExcel',
  exportXls = '/xl/xlCustomerShipment/exportXls',
  xlCustomerShipmentDetailList = '/xl/xlCustomerShipment/queryXlCustomerShipmentDetailByMainId',
  takeDelivery='/xl/xlCustomerShipment/takeDelivery',
  submitTakeDelivery='/xl/xlCustomerShipment/submitTakeDelivery',

  backPass='/xl/xlCustomerShipment/backPass',
  queryOrderByCode='/xl/xlCustomerOrde/queryByCode',  //订单查询

  queryTrack='/xl/kd100/queryTrack',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const xlCustomerShipmentDetailList = Api.xlCustomerShipmentDetailList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

  
/**
 * 订单详情查询接口
 * @param params
 */
export const queryOrderByCode = (params) =>
defHttp.get({url: Api.queryOrderByCode, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


/**
 * 回传快递单号
 * @param params
 */
export const backPassDelivery = (params) => {
  return defHttp.post({url: Api.backPass, params});
}

/**
 * 物流查询
 * @param params
 */
export const queryTrack = (params) => {
  return defHttp.get({url: Api.queryTrack, params});
}

/**
 * 收货
 * @param params
 */
export const takeDelivery = (params) => {
  return defHttp.post({url: Api.takeDelivery, params});
}

/**
 * 收货凭证
 * @param params
 */
export const submitTakeDelivery = (params) => {
  return defHttp.post({url: Api.submitTakeDelivery, params});
}